package com.roy.dsframework.controller;

import com.roy.dsframework.entity.Course;
import com.roy.dsframework.mapper.CourseMapper;
import com.roy.dsframework.service.CourseService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;

/**
 * 使用DynamicDataSource框架，通过@DS注解快速切换数据源
 */

@Controller
@RequestMapping("/DS")
public class CourseControllerDS {
    @Resource
    CourseMapper courseMapper;

    @Resource
    CourseService courseService;

    @ResponseBody
    @RequestMapping("/queryCourse")
    public Object queryOrder(@RequestParam(value = "dsKey", defaultValue = "R") String dsKey) {
//        return courseMapper.selectList(null);
        return courseService.selectCourse();
    }

    @ResponseBody
    @RequestMapping("/createCourse")
    public String createCourse(@RequestParam(value = "dsKey", defaultValue = "W") String dsKey, Course course) {
//        courseMapper.insert(course);
        courseService.createCourse(course);
        return "SUCCESS BY DS";
    }
}
